package core

import (
	"github.com/spf13/viper"
	"log"
	"os"
	"path/filepath"
	"strings"
)

func Viper(configPath string) *viper.Viper {
	if configPath == "" {
		configPath = "../conf/transfer.toml"
	}
	log.Printf("viper config file %v", configPath)
	log.Printf("config Name:%v", strings.Split(filepath.Base(configPath), ".")[0])
	log.Printf("config Path:%v", filepath.Dir(configPath))

	//初始化viper
	viper.SetConfigName(strings.Split(filepath.Base(configPath), ".")[0]) // no need to include file extension
	viper.AddConfigPath(filepath.Dir(configPath))                         // set the path of you config file
	err := viper.ReadInConfig()
	if err != nil {
		log.Fatalf("read config file error:%v:", err.Error())
		os.Exit(1)
	}

	//系统基本配置
	myViper := viper.GetViper()

	return myViper
}
